package com.cn.kabalifemerchants.ui.hall;

import com.cn.kabalifemerchants.api.Api;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.callback.CacheCallBack;
import com.cn.kabalifemerchants.config.Constants;
import com.cn.kabalifemerchants.ui.hall.bean.HallListBean;
import com.cn.kabalifemerchants.ui.login.bean.MsgBean;
import com.cn.kabalifemerchants.ui.page.bean.RecruitListBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/10/20.
 * function:
 */
public class FragmenHallsPresenter extends BasePresenter<FragmenHallsView> {
    public void onHallsListData(String token, int page, int limit) {
        OkGo.<HallListBean>get(Api.API_ROBSERVICE_LIST)
                .headers("token", token)
                .params("page", page)
                .params("limit", limit)
                .execute(new CacheCallBack<HallListBean>() {
                    @Override
                    public void onSuccess(Response<HallListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("抢单：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onHallsListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onHallsgRabBingData(String token, int service_id) {
        OkGo.<MsgBean>post(Api.API_ROBSERVICE_GRABBING)
                .headers("token", token)
                .params("service_id", service_id)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("抢单：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onHallsgRabBingSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
